//
//  SDLastestShopsTableViewController.m
//  Sydeny
//
//  Created by Rainbow on 7/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SDLastestShopsTableViewController.h"

@implementation SDLastestShopsTableViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.listType = SydenyShopListTypeLastest;
    
    UIImageView *logoView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]] autorelease];
    logoView.frame = CGRectMake(0, 0, 94, 29);
    self.navigationItem.titleView = logoView;
    
    SDThreeAdvertisingView *adView = [[SDThreeAdvertisingView alloc] initWithAds:[[CacheData sharedData].advertisings objectForKey:@"0"]];
    adView.delegate = self;
    self.tableView.tableHeaderView = adView;
    [adView release];
    
    [requestParams setObject:@"1" forKey:@"page"];
    [requestParams setObject:[NSString stringWithFormat:@"%d",PER_PAGE_NUMBER] forKey:@"limit"];
    [requestParams setObject:@"10" forKey:@"type"];
    
    [[ServiceHelper sharedService] requestServerForMethod:SydenyRequestGetShops WithParameters:requestParams AndCallBackScope:self AndSuccessSel:@"getShopsSuccess:" AndFailedSel:@"getShopsFailed:"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshData) name:NN_ENTER_FOREGROUND object:nil];
    
}

- (void)refreshData
{
    [[ServiceHelper sharedService] requestServerForMethod:SydenyRequestGetShops WithParameters:requestParams AndCallBackScope:self AndSuccessSel:@"getShopsSuccess:" AndFailedSel:@"getShopsFailed:"];
}

- (void)viewDidUnload
{
    
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (UIView *)tableView:(UITableView *)_tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *bgView = [super tableView:_tableView viewForHeaderInSection:section];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 20)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:14];
    label.text = @"最新资讯";
    [bgView addSubview:label];
    [label release];
    return bgView;
}

@end
